package juc.waitNotify;

import lombok.extern.slf4j.Slf4j;

import static juc.Sleeper.sleep;

@Slf4j(topic = "c.WaitNotifyStep1")
public class WaitNotifyStep1 {

    static final Object room = new Object();
    static boolean hasTool = false;
//    static boolean hasTakeout = false;

    public static void main(String[] args) {
        new Thread(() -> {
            synchronized (room) {
                log.debug("有工具没？[{}]", hasTool);
                if (!hasTool) {
                    log.debug("没工具，先歇会！");
                    sleep(2);
                }
                log.debug("有工具没？[{}]", hasTool);
                if (hasTool) {
                    log.debug("可以开始干活了");
                }
            }
        }, "小帅").start();
        for (int i = 0; i < 5; i++) {
            new Thread(() -> {
                synchronized (room) {
                    log.debug("可以开始干活了");
                }
            }, "其它人").start();
        }
        sleep(1);
        new Thread(() -> {
// 这里能不能加 synchronized (room)？
            hasTool = true;
            log.debug("工具到了噢！");
        }, "送工具的").start();
    }
}
